Add resource: github_repository_files#3456
Open
novucs wants to merge 1 commit into
Open
Conversation
|
👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #2909
Before the change?
When
parallel_requests = trueis set on the provider, managing many files in a single repository viagithub_repository_filewithfor_eachfails frequently with HTTP 409 errors:Cause: each
github_repository_fileinstance issues an independentPUT /contents/{path}(Contents API), which creates one commit per file. Under Terraform's parallelism, the second concurrent write sees a branch SHA that has already advanced past the SHA it captured, and GitHub rejects it viaoptimistic-concurrency check. Setting
parallel_requests = falseserializes HTTP at the transport layer but is documented as experimental, slows down all provider work globally, and still produces N commits when the user really wanted one.The underlying mismatch is semantic: users want one commit containing N files, but the resource model is one resource per file.
After the change?
Adds a new resource,
github_repository_files, that manages a set of files within a branch and writes them all in a single commit per apply via the Git Data API:Git.GetRef→Git.GetCommitto capture the base commit + tree.Git.CreateBlobfor each file content (bounded parallelism).Git.CreateTree(baseTree, entries)— a partial tree merged onto the current base, so unmanaged files in the repo are preserved.Git.CreateCommit+Git.UpdateRef.UpdateRef(branch advanced under us), re-read HEAD, rebase the change onto the new base, and retry. Bounded to 3 attempts with exponential backoff. Blobs are reused across retries because they're content-addressed.Highlights:
file {}blocks the resource owns. Removes the 409-conflict failure mode entirely for users convertingfor_eachpatterns over a single repo.overwrite_on_createflag.file {}blocks are never touched — the merged-tree commit only adds/updates listed paths and deletes paths that were removed from the configuration.parallel_requests = trueuse case works.github_repository_fileis unchanged — users opt in by switching.Example, applied directly to the reporter's config:
Mirrors the conventions of the existing resource:
repository_id+CustomizeDiff: diffRepositoryfor repo-rename detection, computedref/commit_sha/tree_sha/ per-filesha,commit_author/commit_emailpairing,deleteResourceOn404AndSwallow304OtherwiseReturnErrorfor ETag-cached reads,and
handleArchivedRepoDeletefor archived-repo destroys.Docs include a "Differences from
github_repository_file" section (intentionally-omitted attributes) and a "Migrating fromgithub_repository_file" guide with theterraform state rm+terraform importworkflow.Pull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!